import 'package:freedom/page/mahjong/common/message_content.dart';

import 'abstract_message.dart';
import 'action_message.dart';
import 'chart_message.dart';

class MessageHandler {
  MessageHandler._();

  static MessageHandler? _instance;
  late Map<int, AbstractMessageHandler> messageStrategy = {
    /*  MessageContent.MT_VOICE: VoiceMessageHandler(), */
    MessageContent.MT_CHAT: ChartMessageHandler(),
    MessageContent.MT_ACT: ActionMessageHandler()
  };

  factory MessageHandler() {
    _instance ??= MessageHandler._();
    return _instance!;
  }

  void doMessage(MessageContent messageContent) {
    if (messageContent.type == null) {
      return;
    }
    if (!messageStrategy.containsKey(messageContent.type)) {
      return;
    }
    messageStrategy[messageContent.type]?.doMessage(messageContent);
  }
}
